﻿using ml.Supervised;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.AzureAD.XPrize.TwittOracle.Algorithms
{
    public class Perceptron
    {
        private IPredict<TwitterAccount> predictor;
        private const string modelPath = "Data\\perceptron_model.xml";

        public void Generate()
        {
            Console.WriteLine("Loading data..");
            TwitterAccount[] trainData = TwitterAccount.GetData();

            Console.WriteLine("Generating model...");
            var model = new PerceptronModel<TwitterAccount>();
            predictor = model.Generate(trainData);

            Console.WriteLine("Saving model...");
            predictor.Save(modelPath);

            Console.WriteLine("Done");
        }

        public TwitterAccount Test(TwitterAccount account)
        {
            if(predictor == null)
            {
                var model = new PerceptronModel<TwitterAccount>();
                predictor = model.Load(modelPath);
            }

            return predictor.Predict(account);
        }
    }
}
